package com.baichuan.zntx.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.baichuan.common.idempotent.annotation.RepeatSubmit;
import com.baichuan.common.log.annotation.Log;
import com.baichuan.common.web.core.BaseController;
import com.baichuan.common.mybatis.core.page.PageQuery;
import com.baichuan.common.core.domain.R;
import com.baichuan.common.core.validate.AddGroup;
import com.baichuan.common.core.validate.EditGroup;
import com.baichuan.common.log.enums.BusinessType;
import com.baichuan.common.excel.utils.ExcelUtil;
import com.baichuan.zntx.domain.vo.TrackVo;
import com.baichuan.zntx.domain.bo.TrackBo;
import com.baichuan.zntx.service.ITrackService;
import com.baichuan.common.mybatis.core.page.TableDataInfo;

/**
 * 股道管理
 *
 * @author Baichuan
 * @date 2024-05-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zntx-app/track")
public class TrackController extends BaseController {

    private final ITrackService trackService;

    /**
     * 查询股道管理列表
     */
    @SaCheckPermission("zntx-app:track:list")
    @GetMapping("/list")
    public TableDataInfo<TrackVo> list(TrackBo bo, PageQuery pageQuery) {
        return trackService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出股道管理列表
     */
    @SaCheckPermission("zntx-app:track:export")
    @Log(title = "股道管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TrackBo bo, HttpServletResponse response) {
        List<TrackVo> list = trackService.queryList(bo);
        ExcelUtil.exportExcel(list, "股道管理", TrackVo.class, response);
    }

    /**
     * 获取股道管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zntx-app:track:query")
    @GetMapping("/{id}")
    public R<TrackVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(trackService.queryById(id));
    }

    /**
     * 新增股道管理
     */
    @SaCheckPermission("zntx-app:track:add")
    @Log(title = "股道管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TrackBo bo) {
        return toAjax(trackService.insertByBo(bo));
    }

    /**
     * 修改股道管理
     */
    @SaCheckPermission("zntx-app:track:edit")
    @Log(title = "股道管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TrackBo bo) {
        return toAjax(trackService.updateByBo(bo));
    }

    /**
     * 删除股道管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("zntx-app:track:remove")
    @Log(title = "股道管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(trackService.deleteWithValidByIds(List.of(ids), true));
    }
}
